<template>
    <div class="retailmember">
        <van-pull-refresh v-model="refreshing" @refresh="OnRefresh">
            <van-list
                v-model:loading="loading"
                :finished="finished"
                finished-text="没有更多了"
                @load="OnLoad"
            >
                <div class="item" v-for="item in list" :key="item.id">
                    <div class="left">
                        <div class="img">
                            <img :src="item.avatar_cdn" />
                        </div>
                        <div class="content">
                            <div class="nickname">{{ item.nickname }}</div>
                            <div class="tel">{{ item.mobile }}</div>
                        </div>
                    </div>
                    <div class="right">{{ item.createtime_text }}</div>
                </div>
            </van-list>
        </van-pull-refresh>
    </div>
</template>

<script setup>
const { proxy } = getCurrentInstance();

const business = proxy.$business;
const refreshing = ref(false);
const loading = ref(false);
const finished = ref(false);
const list = ref([]);
const page = ref(1);

const OnRefresh = () =>
{
    refreshing.value = true;
    loading.value = true;
    finished.value = false;
    list.value = [];
    page.value = 1;

    setTimeout(OnLoad,1500);
}

const OnLoad = async () =>
{
    if(refreshing.value === true)
    {
        refreshing.value = false;
    }

    const params = {
        busid:business.value.id,
        page:page.value
    }

    const result = await proxy.$http.post('/sale/business',params);

    loading.value = false;

    if(result.code === 1)
    {
        let count = result.data.count;
        list.value = list.value.concat(result.data.list);

        if(list.value.length >= count)
        {
            finished.value = true;

            return false;
        }

        page.value += 1;
    }else{
        finished.value = true;

        proxy.$fail(result.msg);
    }
}
</script>

<style scoped>
@import url('/assets/css/SaleBusiness.css');
</style>
